#!/bin/bash

read -p "请输入要查询的用户名：" username

echo "------------------------------"

user_info=$(getent passwd "$username")

if [ -z "$user_info" ]; then
  echo -e "\e[31m该用户不存在！\e[0m"
  echo "------------------------------"
else
  echo "该用户的用户名：$username"
  echo "该用户的UID：$(echo "$user_info" | awk -F: '{print $3}')"
  echo "该用户的组为：$(id -gn "$username")"
  echo "该用户的GID为：$(echo "$user_info" | awk -F: '{print $4}')"
  echo "该用户的家目录为：$(echo "$user_info" | awk -F: '{print $6}')"
  shell=$(echo "$user_info" | awk -F: '{print $NF}')
  if [ "$shell" == "/bin/bash" ]; then
    echo -e "\e[32m该用户有登录系统的权限\e[0m"
    echo "------------------------------"
  elif [ "$shell" == "/sbin/nologin" ]; then
    echo -e "\e[31m该用户没有登录系统的权限！\e[0m"
    echo "------------------------------"
  fi
fi
